<?php

class Db_access extends Model {

    //constructor creates instance of model
	function Db_access()
	{
		parent::Model();
                //loads the database settings
                $this->load->database();
 
        }
        //selects all of the pet records from the database, saves them to an array and returns the array
   function load_pets(){
  $this->db->select('name, species, breed, descript, notes, pic1, pic2');
  $this->db->from('Pet');
  $query = $this->db->get();
  $pets = $query->result();
 
return $pets;

}  

//selects the pet records from the database,matching the search string parameter and the saves them to an array, then returns the array
function load_selected_pets($searchstring){


return $this->db->like('name',$searchstring)
                         ->or_like('name',$searchstring)
                         ->or_like('species',$searchstring)
                         ->or_like('breed',$searchstring)
                         ->or_like('descript',$searchstring)
                         ->or_like('notes',$searchstring)->get('Pet')->result();
}
//removes pet record where the pet_id equals the $pet_id variable
function remove_pet($pet_id) {
      $this->db->where('pet_id', $pet_id);
 $this->db->delete('Pet');
  }
  //takes an array parameter and inserts it into the database
function insert_pet($petarray) {
      $this->db->insert('Pet', $petarray);

  }
  //takes 2 parameters, updates database with $pet_array where pet_id is equal to $pet_id
function edit_pet($petarray, $pet_id) {

    $this->db->where('pet_id', $pet_id);
 $this->db->update('Pet', $petarray);

  }

// takes a single parameter, selects pet record from database where name equals $petname
function load_pet($petname){

  $this->db->select('pet_id, name, species, breed, descript, notes, pic1, pic2');
  $this->db->from('Pet');
  $this->db->where('name',$petname);
  $query = $this->db->get();
  $pet = $query->result();
 
return $pet;

}
// method for checking login credentials
function login_check($login_name,$password){
//retrieves User record from database for password comparison
       $result = $this->db->get_where('User',array('login_name'=>$login_name))->row();
       //checks the password and returns true or false
       if ($result && $result->password == $password){
               return TRUE;
       }
       return FALSE;
}
//takes one parameter $about_us setss it to an array and uploads it to the database
 function save_about_us($about_us) {
      $data = array('about_us' => $about_us);
      $this->db->where('about_id', 1);
 $this->db->update('About', $data);
  }
//Selects about_us text from About table in database
function load_about_us(){
$about = "blank";
  $this->db->select('about_us');
  $this->db->from('About');
  $this->db->where('about_id', 1);

  $dbabout = $this->db->get();
  
  foreach ($dbabout->result() as $row)
{
  $about = $row->about_us;
}
  return $about;

}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/subshop.php */